new Vue({
    el: '#app',
    mixins: [Query],//组件配置文件，路径/utils/components.js
    data() {
        return {
            form: {//查询筛选
                value: '',
                PageNumber: 1, //页码
                RowAmount: 20,
                Condition: utf8ToBase64("%%"),
            },
        }
    },
    mounted() {
        /**
         * 组件配置文件中自动执行方法
         * 1.this.getColumn(); //查询表头数据
         * 2.this.getList(this.form); //查询表格数据
         * 3.this.getTreeData();//查询树
         */
    },
    methods: {
        handleSerach() { //筛选
            this.form.Condition = utf8ToBase64(`%${this.form.value}%`);
            this.getList(this.form);
        },
        getTreeData() {
            try {
                const { tableName, nodeCode } = $('#tree').data('options');
                httpRequest({
                    url: '/generalBusiness/generalQueryForObtainingTrees',
                    data: {
                        TableName: tableName,
                        NodeCode: nodeCode
                    },
                    type: "GET"
                }).then(tree => {
                    httpRequest({
                        url: '/generalBusiness/generalQueryByTableName',
                        data: {
                            Data: 'crop',
                            Condition: `Row_Status='0'`
                        },
                        type: "GET"
                    }).then(data => {
                        this.configTree(tree, data);
                        this.treeData = tree;
                    }).catch(xhr => {
                        this.$message({
                            message: '系统错误，请联系开发者!',
                            type: 'error'
                        })
                    })
                }).catch(xhr => {
                    this.$message({
                        message: '系统错误，请联系开发者!',
                        type: 'error'
                    })
                })
            } catch (error) { }
        },
        configTree(tree, arr, is = true) {
            tree.forEach(item => {
                if (is) {//树状图结构拼接
                    item.isType = 'crop_type';
                    if (item.children && item.children.length > 0) {
                        this.configTree(item.children, arr);
                    } else {
                        item.children = arr.filter(i => i.Parent_SerialNumber == item.Crop_Type_SerialNumber);
                        item.children.forEach(obj => {
                            obj.Crop_Type_SerialNumber = obj.Crop_SerialNumber;
                            obj.Crop_Type_Name = obj.Crop_Name;
                            obj.isType = 'crop';
                        })
                    }
                } else {//点击节点返农产品主键
                    if (item.isType == 'crop_type') {
                        this.configTree(item.children, arr, false);
                    } else {
                        arr.push(item.Crop_Type_SerialNumber);
                    }
                }
            })
        },
        handleNodeClick(data) {
            if (data.isType == 'crop_type') {
                this.form.value = '';
                let arr = [];
                this.configTree(data.children, arr, false);
                let str = arr.map(i => `crop.Crop_SerialNumber='${i}'`).join(' OR ');
                this.form.ExtensionCondition = utf8ToBase64(`AND (${str})`);
            } else if (data.isType == 'crop') {
                this.form.value = data.Crop_Type_Name;
                this.form.ExtensionCondition = '';
            }
            this.form.Condition = utf8ToBase64(`%${this.form.value}%`);
            this.getList(this.form);
        },
    }
})